<?php
namespace Admin\Controller;
use Think\Controller;

class FundingController extends \Org\Util\AdminController {


    /**
     * 权限验证标志位,默认false
     * false:所有action都需要权限验证;
     * true:所有action都不需要权限验证;
     * array:array中的action不需要权限验证，其余需要。
     */
    protected $notAuthority = false;


    /**
     * 创建之后做的事情
     */
    public function interfaceAfterCreate($id) {
    }

    /**
     * 删除之前做的事情
     */
    public function interfaceBeforeDelete($id) {
    }

    /**
     * 更新之前做的事情
     */
    public function interfaceBeforeUpdate($id) {
    }

    /**
     * 父类中已经有典型的CRUD操作并预留入口
     * 如有较大改动则覆盖一下
     */
    public function create() {
        parent::create();
    }

    public function delete() {
        parent::delete();
    }

    public function update($id) {
        parent::update($id);
    }

    public function list() {
    	$_GET["searchMap"]['transaction_type'] = ['neq','购买'];
        parent::list();
    }

    public function detail($id = 0) {
        parent::detail($id);
    }

    public function import() {
        parent::import();
    }

    public function export() {
        parent::export();
    }

    public function tableOpeationButton() {
        $return  = '
                                <if condition="$vo[state] eq \'待审核\'">
                                    <a class="" href="__CONTROLLER__/check/id/{$vo[id]}" >
                                        <button class="btn btn-xs btn-success" style="border: 1px;">
                                            <i class="icon-check"></i>
                                        </button>
                                    </a>
                                </if>
                                <if condition="($vo[state] eq \'众筹中\') AND ($vo[transaction_type] eq \'发起\')">
                                    <a class="" href="__MODULE__/FundingMerge/list?id={$vo[id]}" >
                                        <button class="btn btn-xs btn-success" style="border: 1px;">
                                            <i class="icon-beaker"></i>
                                        </button>
                                    </a>
                                </if>
                                    <a class="" href="__MODULE__/FundingOrder/list?searchMap[funding_id]={$vo[name]}" >
                                        <button class="btn btn-xs btn-info" style="border: 1px;">
                                            <i class="icon-group"></i>
                                        </button>
                                    </a>';
        return $return;
    }
    public function check($id) {
        $funding = D('Funding')->find($id);
        if ($funding['transaction_type'] == '定制') {
            D('Funding')->where(['id'=>$id])->data(['state'=>'待支付'])->save();
        } else {
            D('Funding')->where(['id'=>$id])->data(['state'=>'众筹中'])->save();            
        }
        $this->success('审核成功!', U('Funding/list'));
    }
    public function game($id) {
        $funding = D('Funding')->find($id);
        if ($funding['game'] == 0) {
            D('Funding')->where(['id'=>$id])->data(['game'=>1])->save();
        } else {
            D('Funding')->where(['id'=>$id])->data(['game'=>0])->save();            
        }
        $this->success('修改成功!');
    }
}
